package org.ssp.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.ssp.base.ResultSetHanlder;
import org.ssp.dao.VisaDao;
import org.ssp.pojo.Visa;
import org.ssp.util.DBUtil;

public class VisaImpl implements VisaDao{

	@Override
	public void add(Visa visa) {
		String sql="insert into visa(id,content,dattime) values(1,?,curdate());";
		DBUtil.update(sql, visa.getContent());
	}

	@Override
	public Visa find() {
		String sql="select * from visa where id=1;";
		return (Visa)DBUtil.query(sql, new ResultSetHanlder() {
			
			@Override
			public Object doHandler(ResultSet rs) {
				Visa visa=null;
				try {
					if(rs.next()){
						visa=new Visa();
						visa.setId(rs.getInt("id"));
						visa.setContent(rs.getString("content"));
						visa.setDatetime(rs.getDate("dattime"));
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
				return visa;
			}
		}, null);
	}
	@Override
	public void update(Visa visa) {
		String sql="update visa set content=? where id=1; ";
		DBUtil.update(sql, visa.getContent());
	}
	@Override
	public void delete() {
		String sql="truncate table visa;";
		DBUtil.update(sql, null);
		
	}

}
